package org.dualr.litelog.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dualr.litelog.dao.PostDao;
import org.dualr.litelog.entity.Post;
import org.dualr.litelog.utils.LiteLogUtil;

@SuppressWarnings("serial")
public class RssServlet extends HttpServlet {
	// private static final Logger log =
	// Logger.getLogger(ArticleServlet.class.getName());

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		int indexEnd = 12;
		String rssCount =null;
		rssCount = LiteLogUtil.getInstance().getPropsValue("/litelog.properties", "litelog.rssCount");
		if(rssCount != null){
			indexEnd = Integer.parseInt(rssCount);
		}
		List<Post> postList = PostDao.getInstance().getPostByRange(0, indexEnd);
		req.setAttribute("PostList", postList);
		try {
			req.getRequestDispatcher("rss.jsp").forward(req, resp);
		} catch (ServletException e) {
			e.printStackTrace();
		}
	}
}
